package com.zhonghui.procurement.service.Impl;

import com.zhonghui.procurement.domain.ProcurementList;
import com.zhonghui.procurement.domain.ProcurementMark;
import com.zhonghui.procurement.domain.ProcurementPush;
import com.zhonghui.procurement.domain.vo.PurchaseAnnouncementVo;
import com.zhonghui.procurement.mapper.ProcurementListMapper;
import com.zhonghui.procurement.mapper.ProcurementMarkMapper;
import com.zhonghui.procurement.mapper.ProcurementPushMapper;
import com.zhonghui.procurement.service.ProcurementListService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

@Service
public class ProcurementListServiceImpl implements ProcurementListService {

    @Autowired
    private ProcurementListMapper procurementListMapper;

    @Autowired
    private ProcurementPushMapper procurementPushMapper;

    @Autowired
    private ProcurementMarkMapper procurementMarkMapper;


    @Override
    public List<ProcurementList> getProcurementList(Integer type,Integer announcementType,String title) {
        List<ProcurementList> procurementList = procurementListMapper.getProcurementList(type,announcementType,title);
        return procurementList;
    }

    @Override
    public ProcurementList getProcurementListItem(int id) {
        ProcurementList procurementList = procurementListMapper.getProcurementListItem(id);

        procurementListMapper.updateReaderNumber(id);
        return procurementList;
    }

    @Override
    @Transactional
    public int insertProcurementList(PurchaseAnnouncementVo purchaseAnnouncementVo) {
//       新增公告
        int i = procurementListMapper.insertProcurementList(purchaseAnnouncementVo);

//       新增推送
        Integer listId = purchaseAnnouncementVo.getListId();
        ProcurementPush procurementPush = new ProcurementPush();
        procurementPush.setListId(Long.valueOf(listId));
        Date now = new Date();
        Timestamp databaseDateTime = new Timestamp(now.getTime());
        procurementPush.setCreateTime(databaseDateTime);
        procurementPushMapper.insertProcurementPush(procurementPush);

        ProcurementMark procurementMark = new ProcurementMark();
        procurementMark.setEndTime(purchaseAnnouncementVo.getEndTime());
        procurementMark.setAnnouncementId(listId);
        procurementMark.setBidType(4);
        procurementMark.setTitle(purchaseAnnouncementVo.getTitle());
//        新增标表
        procurementMarkMapper.insertAdd(procurementMark);
        return i;
    }

    /**
     * 查询采购-公告法规动态列表
     *
     * @param procurementList 采购-公告法规动态
     * @return 采购-公告法规动态
     */
    @Override
    public List<ProcurementList> selectProcurementListList(ProcurementList procurementList)
    {
        return procurementListMapper.selectProcurementListList(procurementList);
    }

    /**
     * 修改采购-公告法规动态
     *
     * @param procurementList 采购-公告法规动态
     * @return 结果
     */
    @Override
    public int updateProcurementList(ProcurementList procurementList)
    {
        return procurementListMapper.updateProcurementList(procurementList);
    }

    /**
     * 删除采购-公告法规动态信息
     *
     * @param listIds 采购-公告法规动态主键
     * @return 结果
     */

    @Override
    public int deleteProcurementListByListIds(Long[] listIds) {
        return procurementListMapper.deleteProcurementListByListIds(listIds);
    }


}
